package com.example.demo.controller;


import com.example.demo.Service.IProductPageService;
import com.example.demo.entity.vo.ProductPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/products")
public class ProductPageController {

    @Autowired
    private IProductPageService productPageService;

    @GetMapping("/page")
    public Map<String,Object> page(Integer pageNum, Integer pageSize , Long categoryId, Long productId){

        List<ProductPageVo> productPageVos = productPageService.list(pageNum, pageSize, categoryId, productId);

        int count = productPageService.count(categoryId);

        Map<String,Object> map = new HashMap<>();

        map.put("total",count);
        map.put("rows",productPageVos);
        map.put("code",200);
        map.put("msg","查询成功");

        return map;

    }




}
